|
1
|
|
|
//var extend = require('util')._extend; |
|
2
|
1 |
|
var extend = require('deep-extend'); |
|
3
|
1 |
|
var fs = require('fs'); |
|
4
|
1 |
|
var path = require('path'); |
|
5
|
1 |
|
var fm = require('front-matter'); |
|
6
|
|
|
|
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* checks for pattern doc options |
|
10
|
|
|
* @param {Patternlibrary} $pl |
|
11
|
|
|
* @returns |
|
12
|
|
|
*/ |
|
13
|
|
|
function checkBase ( $pl ) { |
|
14
|
|
|
|
|
15
|
|
|
// patterns dir |
|
16
|
156 |
|
if (!$pl.options.partials || ($pl.options.partials == '')) { |
|
17
|
2 |
|
throw new Error('To generate pattern documentation a source "partials" path option must be set.'); |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
// destination dir |
|
21
|
154 |
|
if (!$pl.options.dest || ($pl.options.dest == '')) { |
|
22
|
2 |
|
throw new Error('A destination directory "dest" option must be set.'); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
// serving basepath |
|
26
|
152 |
|
if (!$pl.options.basepath || ($pl.options.basepath == '')) { |
|
27
|
2 |
|
throw new Error('An URL "basepath" sub-path option must be set.'); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
// serving patterns sub-path |
|
31
|
150 |
|
if (!$pl.options.patternspath || ($pl.options.patternspath == '')) { |
|
32
|
2 |
|
throw new Error('An URL "patternspath" sub-path option must be set.'); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
// serving categories sub-path |
|
36
|
148 |
|
if (!$pl.options.categoriespath || ($pl.options.categoriespath == '')) { |
|
37
|
2 |
|
throw new Error('An URL "categoriespath" sub-path option must be set.'); |
|
38
|
|
|
} |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* checks for patterns options |
|
43
|
|
|
* @param {Patternlibrary} $pl |
|
44
|
|
|
* @returns |
|
45
|
|
|
*/ |
|
46
|
|
|
function checkPatterns ( $pl ) { |
|
47
|
|
|
|
|
48
|
146 |
|
if (!$pl.options.pattern) { |
|
49
|
1 |
|
throw new Error('The pattern\'s options must be defined.'); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
145 |
|
if (!$pl.options.pattern.dirs) { |
|
53
|
2 |
|
throw new Error('The patterns\' "dirs" sub-path option must be set.'); |
|
54
|
|
|
} |
|
55
|
143 |
|
if (!$pl.options.pattern.dirs.atoms) { |
|
56
|
2 |
|
throw new Error('The patterns\' "atoms" sub-path option must be set.'); |
|
57
|
|
|
} |
|
58
|
141 |
|
if (!$pl.options.pattern.dirs.molecules) { |
|
59
|
2 |
|
throw new Error('The patterns\' "molecules" sub-path option must be set.'); |
|
60
|
|
|
} |
|
61
|
139 |
|
if (!$pl.options.pattern.dirs.organisms) { |
|
62
|
2 |
|
throw new Error('The patterns\' "molecules" sub-path option must be set.'); |
|
63
|
|
|
} |
|
64
|
137 |
|
if (!$pl.options.pattern.dirs.templates) { |
|
65
|
2 |
|
throw new Error('The patterns\' "molecules" sub-path option must be set.'); |
|
66
|
|
|
} |
|
67
|
135 |
|
if (!$pl.options.pattern.dirs.pages) { |
|
68
|
2 |
|
throw new Error('The patterns\' "molecules" sub-path option must be set.'); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
133 |
|
if (!$pl.options.pattern.searchpath) { |
|
72
|
2 |
|
throw new Error('The patterns\' "searchpath" sub-path pattern option must be set.'); |
|
73
|
|
|
} |
|
74
|
131 |
|
if (!$pl.options.pattern.target) { |
|
75
|
20 |
|
throw new Error('The patterns\' "target" filename option must be set.'); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* checks for patterns default doc adapter search-patterns options |
|
82
|
|
|
* @param {Patternlibrary} $pl |
|
83
|
|
|
* @returns |
|
84
|
|
|
*/ |
|
85
|
|
|
function checkPatternsAdapterPatterns ( $pl ) { |
|
86
|
|
|
|
|
87
|
111 |
|
if (!$pl.options.pattern.source) { |
|
88
|
1 |
|
throw new Error('The patterns\' default adapter "source" search pattern option must be set.'); |
|
89
|
|
|
} |
|
90
|
110 |
|
if (!$pl.options.pattern.readme) { |
|
91
|
1 |
|
throw new Error('The patterns\' default adapter "readme" search pattern option must be set.'); |
|
92
|
|
|
} |
|
93
|
109 |
|
if (!$pl.options.pattern.scss) { |
|
94
|
1 |
|
throw new Error('The patterns\' default adapter "scss" search pattern option must be set.'); |
|
95
|
|
|
} |
|
96
|
108 |
|
if (!$pl.options.pattern.javascript) { |
|
97
|
1 |
|
throw new Error('The patterns\' default adapter "javascript" search pattern option must be set.'); |
|
98
|
|
|
} |
|
99
|
107 |
|
if (!$pl.options.pattern.tests) { |
|
100
|
1 |
|
throw new Error('The patterns\' default adapter "tests" search pattern option must be set.'); |
|
101
|
|
|
} |
|
102
|
106 |
|
if (!$pl.options.pattern.changelog) { |
|
103
|
1 |
|
throw new Error('The patterns\' default adapter "changelog" search pattern option must be set.'); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* checks for gui options |
|
110
|
|
|
* @param {Patternlibrary} $pl |
|
111
|
|
|
* @returns |
|
112
|
|
|
*/ |
|
113
|
|
|
function checkGUI ( $pl ) { |
|
114
|
105 |
|
if ($pl.options.nogui === false) { |
|
115
|
84 |
|
if (!$pl.options.gui) { |
|
116
|
1 |
|
throw new Error('GUI options must be defined.'); |
|
117
|
|
|
} |
|
118
|
83 |
|
if (!$pl.options.gui.pages) { |
|
119
|
1 |
|
throw new Error('To generate GUI a source "pages" path option must be set.'); |
|
120
|
|
|
} |
|
121
|
82 |
|
if (!$pl.options.gui.partials) { |
|
122
|
1 |
|
throw new Error('To generate GUI a source "partials" path option must be set.'); |
|
123
|
|
|
} |
|
124
|
81 |
|
if (!$pl.options.gui.layouts) { |
|
125
|
1 |
|
throw new Error('To generate GUI a source "layouts" path option must be set.'); |
|
126
|
|
|
} |
|
127
|
80 |
|
if (!$pl.options.gui.layout) { |
|
128
|
1 |
|
throw new Error('To generate GUI a default "layout" template option must be set.'); |
|
129
|
|
|
} |
|
130
|
79 |
|
if (!$pl.options.gui.docpage) { |
|
131
|
1 |
|
throw new Error('To generate GUI a default "docpage" template option must be set.'); |
|
132
|
|
|
} |
|
133
|
78 |
|
if (!$pl.options.gui.dashboard) { |
|
134
|
1 |
|
throw new Error('To generate GUI a default "dashboard" template option must be set.'); |
|
135
|
|
|
} |
|
136
|
77 |
|
if (!$pl.options.gui.patternlist) { |
|
137
|
1 |
|
throw new Error('To generate GUI a default "patternlist" template option must be set.'); |
|
138
|
|
|
} |
|
139
|
76 |
|
if (!$pl.options.gui.categorylist) { |
|
140
|
1 |
|
throw new Error('To generate GUI a default "categorylist" template option must be set.'); |
|
141
|
|
|
} |
|
142
|
|
|
} |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
/** |
|
146
|
|
|
* checks for static pages options |
|
147
|
|
|
* @param {Patternlibrary} $pl |
|
148
|
|
|
* @returns |
|
149
|
|
|
*/ |
|
150
|
|
|
function checkStaticPages ( $pl ) { |
|
151
|
96 |
|
if ($pl.options.staticpages !== false) { |
|
152
|
96 |
|
if (!$pl.options.root) { |
|
153
|
1 |
|
throw new Error('To generate static pages a source "root" path option must be set.'); |
|
154
|
|
|
} |
|
155
|
95 |
|
if (!$pl.options.layouts) { |
|
156
|
1 |
|
throw new Error('To generate static pages a source "layouts" path option must be set.'); |
|
157
|
|
|
} |
|
158
|
|
|
} |
|
159
|
|
|
} |
|
160
|
|
|
|
|
161
|
|
|
|
|
162
|
1 |
|
module.exports = function(opts) { |
|
163
|
|
|
|
|
164
|
156 |
|
if (!opts) { |
|
165
|
92 |
|
opts = {}; |
|
166
|
|
|
} |
|
167
|
|
|
|
|
168
|
156 |
|
this.options = extend(this.options, { |
|
169
|
|
|
pageRoot : process.cwd() |
|
170
|
|
|
}, opts); |
|
171
|
|
|
|
|
172
|
|
|
|
|
173
|
156 |
|
checkBase(this); |
|
174
|
|
|
|
|
175
|
146 |
|
checkPatterns(this); |
|
176
|
111 |
|
checkPatternsAdapterPatterns(this); |
|
177
|
|
|
|
|
178
|
105 |
|
checkGUI(this); |
|
179
|
|
|
|
|
180
|
96 |
|
checkStaticPages(this); |
|
181
|
|
|
|
|
182
|
94 |
|
return this; |
|
183
|
|
|
} |
|
184
|
|
|
|